// const path = require("path")
const {
    resolve
  
  } = require("path")
  const merge = require("webpack-merge")
  const { bases } = require("./webpack.devbase.config")
  const webpack = require("webpack")
  let entry = [`${process.cwd()}/src/main.js`]
  let plugins = []
  if(process.env.NODE_ENE === "development") {
    entry.unshift("webpack-hot-middleware/client?onInfo=true&reload=true")
    plugins.push(new webpack.HotModuleReplacementPlugin())
  }
  module.exports = merge(bases, { // webpack基于node构建的
    mode: process.env.NODE_ENE, // production
    watch: true,
    watchOptions: {
      poll: 1000,
      // aggregateTimeOut: 500,
      ignored: /node_modules/
    },
  
    entry: entry,
    output: {
      filename: "main.js", // 通过热加载输出script文件挂载在目录与index.HTML一样
      path: resolve(process.cwd(), "dist"),
      publicPath: '/', 
    },
    // production 提供了约定大于配置 约定打包文件是src/index ->dist/main
    devServer: {
      // host: "http://localhost",
      // port: 7000,
      hot: true,
      grogress: true,
      historyApiFallback: true
      // true 表示webpack支持使用history false路由默认是hash
    },
    devtool: "source-map",
    performance: {
      hints: "warning", // false关闭提示 下面设置就没必要了
      // 入口起点的最大体积
      maxEntrypointSize: 50000000,
      // 生成文件的最大体积
      maxAssetSize: 30000000,
      // 只给出 js 文件的性能提示
      assetFilter: function (assetFilename) {
        return assetFilename.endsWith(".js")
      }
    },
    plugins: plugins
  })